{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">活动名：</span>
            <input type="text" name="activity_name" value="{$activity_name}">
            <span class="tbs-txt">报名人真实姓名：</span>
            <input type="text" name="real_name" value="{$real_name}">

            <select name="is_sign" id="is_sign" class="small">
                <option value="-1" {if $is_sign==-1}selected{/if}>-是否签到-</option>
                <option value="0" {if $is_sign==0}selected{/if}>否</option>
                <option value="1" {if $is_sign==1}selected{/if}>是</option>
            </select>
               <!-- <span class="tbs-txt">活动开始时间：</span>-->
                <!--<input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">-->
            <!-- <span class="tbs-txt">添加时间：</span>
             <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">
             <span class="tbs-txt">至</span>
             <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">-->
            <input type="hidden" name="opt" value="select">
            <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
            <!--        <button type="button" class="btn" style="background-color:#FF9900;color:#FFF" onclick="sync_item();">同步商品资料</button>-->


        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            <!--  <col width="5%">
              <col width="5%">
              <col width="5%">
              <col width="10%">-->
            {if $opt == 'passed'}<col width="7%">{/if}
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            <col width="7%">
            {if $opt == 'passed'}<col width="7%">{/if}
            <col width="7%">
            <col width="7%">

        </colgroup>
        <thead>
        <tr>
            {if $opt == 'passed'}<td>选择</td>{/if}
            <td>活动名</td>
            <td>报名人昵称</td>
            <td>职位</td>
            <td>公司名称</td>
            <td>联系电话</td>
            <td>报名人真实姓名</td>
            {if $opt == 'passed'}<td>是否签到</td>{/if}
            <td>支付状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$activity_sign_list  item=activity_sign }
        <tr>
            {if $opt == 'passed'}<td><input type="checkbox" class="checkbox" value="{$activity_sign.activity_sign_id}" name="checkIds[]"></td>{/if}
            <td>{$activity_sign.activity_name}</td>
           <!-- <td>
                <div class="gallery">
                    <div><a href="{$activity.first_pic}"><img src="{$activity.first_pic}" style="width:70px;display:block;"/></a></div>
                    <div class="clear"></div>
                </div>
                &lt;!&ndash;<a href="{$item.link_item}" target="_blank"><img src="{$item.small_img}" alt="" width="50" height="50" onerror="no_pic(this);"></a>&ndash;&gt;
            </td>-->
            <!-- <td>
                 <a href="{$item.link_item}" target="_blank">{$item.item_name}</a>
             </td>-->
            <td>{$activity_sign.nickname}</td>
            <td>{$activity_sign.position}</td>
            <td>{$activity_sign.company_name}</td>
            <td>{$activity_sign.phone}</td>
            <td>{$activity_sign.real_name}</td>
            {if $opt == 'passed'}<td>{if $activity_sign.is_sign==1}是{else}否{/if}</td>{/if}
            <td>{$activity_sign.state}</td>
           <!-- <td>
               {$activity.activity_address}
                &lt;!&ndash; <input type="hidden" name="item_id" value="{$item.item_id}">&ndash;&gt;
            </td>-->
            <td>
                {if $opt == 'passed'}
                <a href="/AcpActivitySign/detail_passed_activity_order/activity_sign_id/{$activity_sign.activity_sign_id}" class="btn" title="订单详情">订单详情</a>
                <a  class="btn" title="修改签到状态" onclick="changestatus({$activity_sign.activity_sign_id})">修改签到</a>
                    {if $activity_sign.pay_status == 1 && $activity_sign.pay_amount > 0}
                    <!-- <a href="javascript:;" class="btn" onclick="refund({$activity_sign.activity_sign_id})">退款</a> -->
                    {/if}
                <a  class="btn" title="删除" onclick="del_activity_sign({$activity_sign.activity_sign_id})">删除</a>
                {/if}

                {if $opt == 'not_passed'}
                <a href="/AcpActivitySign/detail_bypass_activity_order/activity_sign_id/{$activity_sign.activity_sign_id}" class="btn" title="订单详情">订单详情</a>
                <a  class="btn" title="通过" onclick="set_check({$activity_sign.activity_sign_id},1)">通过</a>
                <a  class="btn" title="拒绝" onclick="set_check({$activity_sign.activity_sign_id},2)">拒绝</a>
                {/if}
               <!-- <a href="/AcpActivity/edit_activity_sign/activity_sign_id/{$activity_sign.activity_sign_id}" class="btn" title="编辑">编辑</a>-->
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <div class="fl">
            {if $opt == 'passed'}
            <a href="javascript:selall()" class="btn btn-blue">全选</a>
            <a href="javascript:clearall()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue" onclick="delActivitySignBatch()">删除</a>
            {/if}

            <!--{if $opt == 'not_passed'}-->
            <!--<a  class="btn" title="通过" onclick="batch_set_check()">通过</a>-->
            <!--<a  class="btn" title="拒绝" onclick="batch_set_check()">拒绝</a>-->
            <!--{/if}-->
        </div>
        <div class="fr">
            <div class="paginate">
                {$page->show()}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__ACPJS__/acp_item.js?version={$version}"></script>
<script src="__ACPJS__/AcpItem/list_item.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
{literal}
<script>

    function set_check(obj_id,is_type)
    {
        if(is_type == 2){
            var title= '未通过理由'
            var html='';
            var html='<form id="reason_form">' +
                    '<div class="formitems inline">'+
                    '<label class="fi-name"><span class="colorRed">*</span>未通过理由：</label>'+
                    '<div class="form-controls">'+
                    '<textarea name="content" id="content"></textarea><span class="fi-help-text"> </span>'+
                    '</div>' +
                    '<input type="hidden" name="obj_id" value="'+obj_id+'">'+
                    '<input type="hidden" name="is_type" value="'+is_type+'">'+
                    '<input type="hidden" name="act" value="add">'+
                    '</div>'+
                    '</form>';
        }else if(is_type == 1){
            var title='提示';
            var html ='确定通过审核吗?';
        }

        $.jPops.custom({
            title:title,
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    if(is_type == 1){
                        $.post('/AcpActivitySign/set_check',{obj_id:obj_id,is_type:is_type},function(data)
                        {
                            if (data.code == 1)
                            {
                                alert(data.msg);
                                location.reload();
                            }
                            else
                            {
                                alert(data.msg);
                            }
                        })
                    }

                    if(is_type == 2){
                        $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpActivitySign/set_check',$('#reason_form').serialize(),function(data)
                                    {
                                        if (data.code == 1)
                                        {
                                            alert(data.msg);
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert(data.msg);
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });
                        //表单验证规则
                        $("#reason_form").validate(
                                {
                                    rules:
                                    {
                                        status_cause:
                                        {
                                            required: true
                                        }
                                    },
                                    messages:
                                    {
                                        status_cause:
                                        {
                                            required: "对不起，请填写不通过审核的理由",
                                        }
                                    },
                                    errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                    success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                                });

                        //模拟提交表单
                        $("#reason_form").submit();
                        return acp.batchDeliverFormStatus;
                    }
                }
                else
                {
                    return true;
                }
            }
        });
    }





    var item_name = '{$ITEM_NAME}';

    function sync_item()
    {
        var html = "确定执行此操作，本操作将比较费时，请耐心等候!";
        $.jPops.custom({
            title:"同步商品资料",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $('body').showLoading();
                    $.post('/Global/sync',{},function(data) {
                        $("body").hideLoading();
                        if (data == 'success') {
                            alert('同步成功');
                            location.reload();
                        } else {
                            alert('同步失败，请稍后再试');
                        }
                    });
                }
                return true;
            }
        });
    }
    //复制商品链接
    function item_link(item_id, is_integral)
    {
        if(is_integral == 1){
            action = 'integral_item_detail';
        }else{
            action = 'item_detail';
        }
        var link = 'http://' + document.domain + '/FrontMall/'+action+'/item_id/' + item_id;
        $.jPops.custom({
            title:"请复制链接",
            content:'<div>商品链接：' + link + '</div>',
            okBtnTxt:"复制",
            cancelBtnTxt:"关闭",
            callback:function(r)
            {
                if(r)
                {
                    text = link;
                    copy_text('jpops-btn-ok');
                }
                else
                {
                    return true;
                }
            }
        });
    }
    function del_activity_sign(activity_sign_id){
        console.log(activity_sign_id);
        var html = "确定删除这个报名?";
        $.jPops.custom({
            title:"删除活动",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                console.log(r);
                if(r)
                {
                    $.post('/AcpActivitySign/del_activity_sign',{'activity_sign_id':activity_sign_id},function(data) {
                        if (data == 'success') {
                            alert('删除成功');
                            location.reload();
                        } else {
                            alert('删除失败');
                        }
                    });
                }
                return true;
            }
        });
    }
    //批量删除
    function delActivitySignBatch(){
        var ids='';
        var count='';
        $('input[name="checkIds[]"]:checked').each(function()
        {
            count ++;
            ids += $(this).val() + ',';
        });
        console.log(ids);
        if(count== 0){
            $.jPops.alert({
                title:"提示",
                content:'对不起，请选择要删除项！',
                okBtnTxt:"确定",
                callback:function(){
                    return true;
                }
            });
            return false;
        }
        $.jPops.confirm({
            title:"提示",
            content:'您确定要删除这些数据吗？',
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r){
                if(r){
                    $.ajax({
                        url: '/AcpActivitySign/del_activity_sign_batch',
                        data: {id: ids},
                        type:'post',
                        success: function(data){
                            console.log(data)
                            if(data == 'success'){
                                $.jPops.alert({
                                    title:"提示",
                                    content:'删除成功',
                                    okBtnTxt:"确定",
                                    callback:function(){
                                        window.location.reload();
                                    }
                                });
                            }else{
                                $.jPops.alert({
                                    title:"提示",
                                    content:'删除失败',
                                    okBtnTxt:"确定",
                                    callback:function(){
                                        return true;
                                    }
                                });
                            }
                        }
                    });
                }
                return true;
            }
        });
    }

    //修改签到状态
    function changestatus(activity_sign_id){
        var html = "确定修改?";
        $.jPops.custom({
            title:"修改签到状态",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                console.log(r);
                if(r)
                {
                    $.post('/AcpActivitySign/change_activity_sign',{'activity_sign_id':activity_sign_id},function(data) {
                        if (data == 'success') {
                            alert('修改成功');
                            location.reload();
                        } else {
                            alert('修改失败');
                        }
                    });
                }
                return true;
            }
        });
    }
    function copy_text(id)
    {
        var clipboard = new Clipboard('#' + id, {
            text: function() {
                return text;
            }
        });

        clipboard.on('success', function(e) {
            console.log(e);
            alert('复制成功');
        });

        clipboard.on('error', function(e) {
            console.log(e);
            alert('复制失败，请手动复制');
        });
    }


    //退款
    function refund(order_id){
        
        $.jPops.confirm(
            {
                title: "提示",
                content: "您确定要执行该操作吗？",
                okBtnTxt: "确定",
                cancelBtnTxt: "取消",
                callback: function (r) {
                    if (r) {
                        $.ajax({
                            url:'/AcpActivitySign/refund',
                            type:'post',
                            data:{order_id:order_id},
                            success:function(r){
                                if(r.code == 0){
                                    alert(r.msg);
                                    location.reload();
                                }else if(r.code == 2){
                                    window.location.href = r.link
                                }else{
                                    alert(r.msg);
                                }
                            }
                        })
                    }
                    return true;
                }
            });
            
            

    }
</script>
{/literal}
{/block}
